#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=3e5+10;
ll sum[N];
ll a[N];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			sum[i]=sum[i-1]+a[i];
		}
		ll premax=0;
		ll res=0;
		ll h=0;
		for(int i=1;i<=n;i++)
		{
			if(sum[i]-premax<h)
			{
				h=sum[i]-premax;
				res=premax;
			}
			premax=max(premax,sum[i]);
		}
		cout<<res<<endl;
		
	}

	return 0;
}

